﻿using System;
using System.ComponentModel;
using System.Data;
using System.Data.SqlClient;
using System.Windows;
using System.Windows.Controls;
namespace WPFExcelReport
{
    public partial class UIHR20WEAVER : UIHR
    {
        #region ==MachineName===========
        public static readonly DependencyProperty MachineNameProperty = DependencyProperty.Register("MachineName",
            typeof(string), typeof(UIHR20WEAVER),
            new FrameworkPropertyMetadata("", FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OnMachineNameChanged));
        public string MachineName
        {
            get
            {
                return (string)GetValue(MachineNameProperty);
            }
            set
            {
                SetValue(MachineNameProperty, value);
                OnMachineChg();
            }
        }
        private static void OnMachineNameChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            var src = sender as UIHR20WEAVER;
            if (src != null)
            {
                src.MachineName = (string)e.NewValue;
            }
        }
        public virtual void OnMachineChg()
        {
            //CHKWVER();
        }
        #endregion
        public override void OnSHIFTChg(string value)
        {
            CHKWVER();
            base.OnSHIFTChg(value);
        }

        public virtual void CHKWVER()
        {

        }
        public virtual void CHKWVERHR()
        {

        } 
        public virtual void ShiftProdctionCommand(object sender, RoutedEventArgs e)
        {
            if (dwMain == null)
            { }
            KEY = "";
            if (dwMaster != null)
            {
                KEY = dwMaster["WeaverID"].ToString().Trim().PadRight(10)
                    + dwMaster["WeaverName"].ToString().Trim().PadRight(10)
                    + dwMaster["MachineName"].ToString().Trim().PadRight(10)
                    + dwMaster["ClassTypeID"].ToString().Trim().PadRight(10)
                    + dwMaster["TeamID"].ToString().Trim().PadRight(10)
                    + dwMaster["GroupID"].ToString().Trim().PadRight(10)
                    + QTY.ToString().Trim().PadRight(10);
                QTY = 0;
                TBMain.Clear();
            }
        }
    }
    public partial class VHRSTAMM
    {
        SqlConnection _SqlServerDB;
        SqlConnection SqlServerDB
        {
            get
            {
                if (_SqlServerDB == null)
                    _SqlServerDB = new SqlConnection(app.SqlDB);
                return _SqlServerDB;
            }
        }

        public DataSet QHRRTWVER(string sql)
        {
            SqlCommand SQLCmd;
            SQLCmd = SqlServerDB.CreateCommand();
            SQLCmd.CommandText = "select DISTINCT MC.MachineName AS MachineName,WeaverID,WeaverName,WeaverName as HRNNAME,WeaverNo,CL.ClassTypeID,CL.TeamID,WV.GroupID from tClasslist CL"
                + " inner join tWeaverList WL on CL.ClassListID = WL.ClassListID"
                + " inner join ProductChange PC on PC.MachineID = WL.MachineID"
                + " inner join  Machine MC on MC.MachineID = PC.MachineID"
                + " inner join  tWeaver WV on(WL.WeaverID1 = WV.WeaverID)"
                //+ " inner join  tWeaver WV on(WL.WeaverID1 = WV.WeaverID or WL.WeaverID2 = WV.WeaverID or WL.WeaverID3 = WV.WeaverID or WL.WeaverID4 = WV.WeaverID)"
                + sql
                + " order by 1";
            SResult = INTEXDBC.Connect2Proxy(SQLCmd);
            SResult.Tables[0].TableName = TableName;

            return SResult;
        }
        public DataSet QHRRTWVER2HR()
        { 
            SqlCommand SQLCmd;
            SQLCmd = SqlServerDB.CreateCommand();
            SQLCmd.CommandText = "select DISTINCT WeaverID,WeaverName,WeaverName as HRNNAME,WeaverNo, WeaverID As HRBENID "
                + " from  tWeaver WV   order by 1";
            SResult = INTEXDBC.Connect2Proxy(SQLCmd);
            SResult.Tables[0].TableName = TableName;
            return SResult;
        }
        public DataSet QHRRTDEMO(string sql)
        {

            or1 = OracleDB.CreateCommand();
            or1.CommandText = "select 'A' AS MachineName, 101 AS WeaverID,'ABC' AS WeaverName,'ABC' as HRNNAME,1 AS WeaverNo,2 AS ClassTypeID,3 AS TeamID,4 AS GroupID from DUAL CL";
            SResult = INTEXDBC.Connect2Proxy(or1);
            SResult.Tables[0].TableName = TableName;

            return SResult;
        }
    }
}
